home *** CD-ROM | disk | FTP | other *** search
- /**
- GRAB Graph Layout and Browser System
-
- Copyright (c) 1989, Tera Computer Company
- **/
-
- /**
- Implementation of buttons area
-
- The area contains four buttons with menus attached, and 3 buttons to
- indicate the current mode. Pressing a MenuButton causes a menu to
- popup. The user then selects one of the menu items, which causes a
- routine to be executed. Pressing one of the mode buttons causes that
- button to become the current mode. Only one mode is current at a
- time.
-
- The options button contains many items which indicate which global
- options are set. Because the values of these options can change, it
- must be rebuilt often.
-
- At certain times, pressing buttons is inhibited. At other times,
- pressing buttons changes the outside state.
- **/
-
- #include "istring.h"
- #include "bview.h"
- #include "routines.h"
- #include "gframe.h"
- #include "mymenu.h"
- #include <InterViews/painter.h>
- #include <InterViews/sensor.h>
- #include <InterViews/shape.h>
- #include <InterViews/border.h>
- #include <InterViews/glue.h>
- #include <stdio.h>
- #include <string.h>
-
- /* strings for the options menu */
- static char* otext[numopts] =
- {
- " Print Node Label",
- " Mark Dummy Nodes",
- " Draw Arrows",
- " Print Edge Label",
- " Change In Edges",
- " Change Out Edges",
- " Rotate PostScript File",
- " Show BC",
- " Debug Mode",
- " Straighten Edges",
- " Ignore Hidden"
- };
-
- void commandpress(TextItem*), optionspress(TextItem*);
- void editpress(TextItem*), filepress(TextItem*);
-
- ButtonView::ButtonView ()
- /* build the button area: 4 menu buttons and 3 flipbuttons (mode buttons) */
- {
- MyMenu* m;
- ButtonState* b;
- int i;
-
- b = new ButtonState();
- m = new MyMenu();
- m->Insert(new TextItem("Redisplay Screen", 'a'));
- m->Insert(new TextItem("Redraw Graph", 'b'));
- m->Insert(new TextItem("Layout Graph", 'c'));
- m->Insert(new TextItem("Print Screen (PostScript)", 'd'));
- m->Insert(new TextItem("Show Levels", 'e'));
- m->Insert(new TextItem("Help", 'f'));
- m->Insert(new TextItem("Exit", 'g'));
- m->Compose();
- commandButton = new MenuButton("Commands", b, m, commandpress);
-
- b = new ButtonState();
- m = new MyMenu();
- m->Insert(new TextItem("Change Node Text", 'a'));
- m->Insert(new TextItem("Change Edge Label", 'b'));
- m->Insert(new TextItem("Size to Fit", 'c'));
- m->Insert(new TextItem("Focus on Node", 'd'));
- m->Insert(new TextItem("Focus on Named Node", 'e'));
- m->Insert(new TextItem("Create Checkpoint", 'f'));
- m->Insert(new TextItem("Previous Checkpoint", 'g'));
- m->Insert(new TextItem("Next Checkpoint", 'h'));
- m->Insert(new TextItem("Execute Commands in File", 'i'));
- m->Compose();
- editButton = new MenuButton("Edit", b, m, editpress);
-
- b = new ButtonState();
- m = new MyMenu();
-
- for (i = 0; i < numopts; i++)
- {
- tti[i] = new TextItem(otext[i], 'a' + i);
- m->Insert(tti[i]);
- }
-
- m->Insert(new TextItem("Set Zoom Gradient", 'A'));
- m->Insert(new TextItem("Set Pan Gradient", 'B'));
- m->Insert(new TextItem("Show Layout Stats", 'C'));
- m->Insert(new TextItem("Show Program Stats", 'D'));
- m->Insert(new TextItem("Show Region Sizes", 'E'));
- m->Insert(new TextItem("Dump Node List", 'F'));
- m->Insert(new TextItem("Open Attributes Window", 'G'));
- m->Compose();
- optionsButton = new MenuButton("Options", b, m, optionspress);
-
- b = new ButtonState();
- m = new MyMenu();
- m->Insert(new TextItem("Change File Name", 'a'));
- m->Insert(new TextItem("Read File", 'b'));
- m->Insert(new TextItem("Write File", 'c'));
- m->Insert(new TextItem("Write File (PostScript)", 'd'));
- m->Compose();
- fileButton = new MenuButton("File", b, m, filepress);
-
- bmbstate = new ButtonState();
- cmbstate = new ButtonState();
- embstate = new ButtonState();
- // rrh changed next three calls from DoBrowseMode to &DoBrowseMode (etc)
- // in order to eliminate error messages from g++. DoBrowseMode is
- // an extern C function, not a C++ function. complained about
- // being given a "void (*)()", when it wanted a "auto void (*)()"
- // mysterious
- browseMButton = new FlipButton("Browse", bmbstate, false, true,
- &DoBrowseMode);
- changeMButton = new FlipButton("Change", cmbstate, true, false,
- &DoChangeMode);
- editMButton = new FlipButton("Edit", embstate, true, false, &DoEditMode);
- browseMButton->SetOpp(editMButton, changeMButton);
- editMButton->SetOpp(browseMButton, changeMButton);
- changeMButton->SetOpp(browseMButton, editMButton);
-
- Insert (new HGlue);
- Insert (commandButton);
- Insert (new HGlue);
- Insert (editButton);
- Insert (new HGlue);
- Insert (optionsButton);
- Insert (new HGlue);
- Insert (fileButton);
- Insert (new HGlue);
- Insert (browseMButton);
- Insert (new HGlue);
- Insert (changeMButton);
- Insert (new HGlue);
- Insert (editMButton);
- Insert (new HGlue);
- }
-
- void ButtonView::SetFrame(GraphFrame *frame)
- /**
- the buttons must know about the top-level interactor so they
- can set the cursor to its proper value
- **/
- {
- commandButton->SetFrame(frame);
- editButton->SetFrame(frame);
- optionsButton->SetFrame(frame);
- fileButton->SetFrame(frame);
- browseMButton->SetFrame(frame);
- editMButton->SetFrame(frame);
- }
-
- /**
- Build a new options menu, according to the 'char' array b (b
- really should be a boolean array, but I can't get it passed correctly,
- so char will have to do). In any event, the array indicates which options
- are set and which are not. Those that are set get an asterisk before
- them.
- **/
- static const char on = '*';
- static const char off = ' ';
-
- void ButtonView::NewOptionsMenu(char b[numopts])
- {
- int i;
- MyMenu* m = new MyMenu();
-
- for (i = 0; i < numopts; i++)
- {
- char* buf = strdup(otext[i]);
- buf[0] = b[i] ? on : off;
- // delete tti[i];
- tti[i] = new TextItem(buf, 'a' + i);
- m->Insert(tti[i]);
- }
-
- m->Insert(new TextItem("Set Zoom Gradient", 'A'));
- m->Insert(new TextItem("Set Pan Gradient", 'B'));
- m->Insert(new TextItem("Show Layout Stats", 'C'));
- m->Insert(new TextItem("Show Program Stats", 'D'));
- m->Insert(new TextItem("Show Region Sizes", 'E'));
- m->Insert(new TextItem("Dump Node List", 'F'));
- m->Insert(new TextItem("Set Displayed Attributes", 'G'));
- m->Compose();
- optionsButton->ChangeMenu(m);
- }
-
- MenuButton::MenuButton (char* s, ButtonState* b, MyMenu* m,
- void (*f)(TextItem*)) : (s, b, -1)
- /**
- I'm not sure the buttonstate is worth keeping
- pressf is the function to call when a menu item is selected
- **/
- {
- menu = m;
- bstate = b;
- pressf = f;
- frame = nil;
- }
-
- void MenuButton::SetFrame(GraphFrame* f)
- /* store the value of the top-level interactor */
- {
- frame = f;
- }
-
- void MenuButton::ChangeMenu (MyMenu* m)
- /**
- change the menu this button is associated with (useful for the
- options menu button)
- **/
- {
- delete menu;
- menu = m;
- }
-
- void MenuButton::Handle (Event& e)
- /* on a down event, popup a menu, and call pressf if an item was selected */
- {
- TextItem* i;
-
- if (e.eventType == DownEvent)
- {
- frame->SetCurs(mainC);
- ClearInModeFlag(); /* if we were in a special state, we aren't now */
- menu->Popup(e, i);
-
- if (i != nil)
- {
- this->pressf(i);
- }
- }
- }
-
- FlipButton::FlipButton (char* s, ButtonState* b, int on, int off, void (*f)())
- : (s, b, on, off)
- /**
- a button which is either on or off. If it's on, the other flipbuttons
- are off.
- **/
- {
- pressf = f;
- onval = on;
- offval = off;
- opp1 = nil;
- opp2 = nil;
- frame = nil;
- }
-
- void FlipButton::SetFrame(GraphFrame* f)
- {
- frame = f;
- }
-
- void FlipButton::SetOpp(FlipButton* f1, FlipButton* f2)
- /**
- keep track of who the other flipbuttons are so we can inform them
- when we've been selected
- **/
- {
- opp1 = f1;
- opp2 = f2;
- }
-
- void FlipButton::Press()
- /* if we were off, turn ourselves on and turn the others off */
- {
- ClearInModeFlag(); /* if we were in a special state, we aren't now */
-
- if (!chosen)
- {
- subject->SetValue(onval);
- this->pressf();
- opp1->unpress();
- opp2->unpress();
- }
- }
-
- void FlipButton::unpress()
- {
- subject->SetValue(offval);
- }
-
- void commandpress(TextItem* i)
- /* commands to be executed when command menu items are selected */
- {
- switch (i->tag)
- {
- case 'a':
- DoRedisplay();
- break;
- case 'b':
- DoRedrawGraph();
- break;
- case 'c':
- DoLayoutGraph();
- break;
- case 'd':
- DoPSScreen();
- break;
- case 'e':
- DoShowLevels();
- break;
- case 'f':
- DoHelp();
- break;
- case 'g':
- DoQuit();
- break;
- }
- }
-
- void editpress(TextItem* i)
- /* commands to be executed when edit menu items are selected */
- {
- switch (i->tag)
- {
- case 'a':
- DoChangeText();
- break;
- case 'b':
- DoChangeEdgeLabel();
- break;
- case 'c':
- DoSizeToFit();
- break;
- case 'd':
- DoFocusNode();
- break;
- case 'e':
- DoFocusNamedNode();
- break;
- case 'f':
- DoSaveCkpt();
- break;
- case 'g':
- DoPrevCkpt();
- break;
- case 'h':
- DoNextCkpt();
- break;
- case 'i':
- DoGetCommandsFromFile();
- break;
- }
- }
-
- void optionspress(TextItem* i)
- /* commands to be executed when options menu items are selected */
- {
- switch (i->tag)
- {
- case 'a':
- DoPrintLabel();
- break;
- case 'b':
- DoMarkDummyNodes();
- break;
- case 'c':
- DoDrawArrow();
- break;
- case 'd':
- DoPrintEdgeLabel();
- break;
- case 'e':
- DoChangeInEdges();
- break;
- case 'f':
- DoChangeOutEdges();
- break;
- case 'g':
- DoRotatePSFile();
- break;
- case 'h':
- DoShowBC();
- break;
- case 'i':
- DoDebugMode();
- break;
- case 'j':
- DoStraighten();
- break;
- case 'k':
- DoIgnoreHidden();
- break;
- case 'A':
- DoSetZoomGrad();
- break;
- case 'B':
- DoSetPanGrad();
- break;
- case 'C':
- DoPrintLayoutStats();
- break;
- case 'D':
- DoPrintUsage();
- break;
- case 'E':
- DoShowSize();
- break;
- case 'F':
- DoDumpNodeList();
- break;
- case 'G':
- DoSetDisplayed();
- }
- }
-
- void filepress(TextItem* i)
- /* commands to be executed when file menu items are selected */
- {
- switch (i->tag)
- {
- case 'a':
- DoChangeFileName();
- break;
- case 'b':
- DoReadFile();
- break;
- case 'c':
- DoWriteFile();
- break;
- case 'd':
- DoCreatePSFile();
- break;
- }
- }
-